package com.eleven.mall.controller;

import com.eleven.mall.pojo.Menu;
import com.eleven.mall.pojo.Rbody;
import com.eleven.mall.service.RightService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Auther: Rui_simple
 * @Date: 2022/10/21 15:09
 * @Description: RightController
 * @Version 1.0.0
 */
@RestController
@CrossOrigin
@AllArgsConstructor
public class RightController {

    RightService rightService;

    @GetMapping("/menus")
    public Rbody getMenus(HttpServletRequest request){
        Rbody rbody = new Rbody();
        String token = request.getHeader("Authorization");
        //System.out.println(token);
        Integer userId = (Integer) request.getAttribute("userId");
        //System.out.println(userId);
        List<Menu> menuList = rightService.getMenusByUserId(userId);
        rbody.setData(menuList);
        System.out.println(token+userId);
        return rbody;
    }
}
